package org.stvd.service.oauth;

import javax.sql.DataSource;

import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices;

public class SOSAuthorizationCodeServices extends JdbcAuthorizationCodeServices {

    public SOSAuthorizationCodeServices(DataSource dataSource) {
        super(dataSource);
    }
    
    //自定义授权码长度为12位,默认6位
    private RandomValueStringGenerator generator = new RandomValueStringGenerator(12);
    
    @Override
    public String createAuthorizationCode(OAuth2Authentication authentication) {
        String code = generator.generate();
        store(code, authentication);
        return code;
    }

    @Override
    protected void store(String code, OAuth2Authentication authentication) {
        super.store(code, authentication);
    }

    @Override
    public OAuth2Authentication remove(String code) {
        return super.remove(code);
    }
}
